package com.mediacloud.app.newsmodule.fragment.navlive

import android.content.Context
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapterX

class NavLiveProgramDateAdapter(context:Context):BaseRecyclerAdapterX<NavDateItem>(context)
{

    var selectedIndex:Int=0
    set(value)
    {
        field=value
        notifyDataSetChanged()
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):RecyclerView.ViewHolder
    {
        return ProgramDateHolder(LayoutInflater.from(getContext()).inflate(R.layout.navprogram_dateitem,parent,false))
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int)
    {
        super.onBindViewHolder(holder, position)
        if(holder is ProgramDateHolder)
        {
            holder.update(position==selectedIndex,getItem(position))
        }
    }

    class ProgramDateHolder(itemView: View) :RecyclerView.ViewHolder(itemView)
    {
        val navDayTxt:TextView=itemView.findViewById(R.id.navDayTxt)
        val navDateTxt:TextView=itemView.findViewById(R.id.navDateTxt)

        val c1= ContextCompat.getColor(itemView.context,R.color._222)
        val c2= ContextCompat.getColor(itemView.context,R.color.cctv7_red_light)
        fun update(isSelected: Boolean,dateItem: NavDateItem)
        {
            if(!isSelected){
                navDateTxt.setBackgroundResource(0)
                navDateTxt.setTextColor(c1)
                navDayTxt.setTextColor(c1)
            }
            else{
                navDayTxt.setTextColor(c2)
                navDateTxt.setTextColor(c2)
            }

            navDateTxt.text=dateItem.date_format
            navDayTxt.text=dateItem.title
        }


    }

}